package com.go.ssh.point.dao.hibernate;

import java.util.ArrayList;
import java.util.List;

import com.go.ssh.commons.dao.hibernate.BaseHibernateDao;
import com.go.ssh.point.dao.IAccountDao;
import com.go.ssh.point.model.RoleModel;
import com.go.ssh.point.model.UserModel;

public class AccountHibernateDao extends BaseHibernateDao<UserModel, Integer>
		implements IAccountDao {

	@Override
	public UserModel get(String username, String password) {
		String hql = getListAllHql() + " where username = ? and password = ?";
		List<UserModel> users = list1(hql, username, password);
		return users == null ? null : users.get(0);
	}

	@Override
	public List<RoleModel> getRoles(String username) {
		// TODO
		List<RoleModel> roles = new ArrayList<RoleModel>();
		RoleModel role = new RoleModel();
		role.setRole("admin");
		role.setRoleName("管理员");
		roles.add(role);
		role = new RoleModel();
		role.setRole("account");
		role.setRoleName("注册用户");
		roles.add(role);

		return roles;
	}

	@Override
	public UserModel get(String username) {
		String hql = getListAllHql() + " where username = ?";
		return unique(hql, username);
	}
}
